package per.jdz.lock8;

import java.util.concurrent.TimeUnit;

public class Test2 {
    public static void main(String[] args) {
        Phone2 phone = new Phone2();
        Phone2 phone2 = new Phone2();
        new Thread(phone::sendSms).start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        // new Thread(phone2::call).start();
        new Thread(phone2::hello).start();
    }
}

class Phone2 {

    // synchronized锁的是方法的调用者
    public synchronized void sendSms() {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("send sms");
    }

    public synchronized void call() {
        System.out.println("call phone");
    }
    public void hello() {
        System.out.println("hello");
    }
}

